package com.lry.basic.jvm.asm.transform_class.demo11;

import aj.org.objectweb.asm.ClassReader;
import aj.org.objectweb.asm.ClassVisitor;
import aj.org.objectweb.asm.ClassWriter;
import com.lry.basic.jvm.asm.utils.FileUtils;

import java.lang.reflect.Field;

import static aj.org.objectweb.asm.Opcodes.ASM4;

public class Test {

    public static void main(String[] args) throws Exception {
//        String relativePath = "com/lry/basic/jvm/asm/transform_class/demo11/HelloWorld.class";
//        String filePath = FileUtils.getFilePath(relativePath);
//        byte[] b = FileUtils.readBytes(filePath);
//
//        ClassReader cr = new ClassReader(b);
//
//        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
//
//        ClassVisitor cv = new MethodTimerVisitor(ASM4,cw);
//
//        cr.accept(cv,ClassReader.SKIP_DEBUG|ClassReader.SKIP_FRAMES);
//
//        byte[] b2 = cw.toByteArray();
//
//        FileUtils.writeBytes(filePath, b2);

        test();

    }

    private static void test() throws Exception {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.test("lry");

        Field field = HelloWorld.class.getDeclaredField("timer");
        field.setAccessible(true);
        System.out.println("cost ms:"+field.get(null));

    }

}
